﻿
<?php

ignore_user_abort(TRUE);
require_once("./interface.php");
require_once("./utils.php");
require_once("./TechnicFunc.php");
require_once("./SoldierFunc.php");
require_once("./HotelFunc.php");
require_once("./OfficeFunc.php");
require_once("./MarketFunc.php");
require_once("./UnionFunc.php");
require_once("./StoreFunc.php");
require_once("./TroopFunc.php");
require_once("./global.php");
require_once("./report.php");
require_once("./bin_ss.php");
require_once("./bin_rank.php");





function goodsdrop($binbin)
{

//$con = mysql_connect("127.0.0.1","root","111111");
//if (!$con)
  //{
  //die('Could not connect: ' . mysql_error());
  //}
//mysql_select_db("sanguo1", $con);//链接数据库
$goods_drop_time=time();
$g_t_id=$binbin;
$uid =sql_fetch_one_cell("select uid from sys_troops where `id`='$g_t_id'");

//====掉落的概率
$goods_drop_rat1=mt_rand(1,3);//道具获得概率
$goods_drop_rat2=mt_rand(1,10);//装备获得概率
$goods_drop_rat3=mt_rand(1,2);//史诗任务物品获得概率
$goods_drop_rat4=mt_rand(1,4);//元宝获得概率

$goods_drop_1=9999;
$goods_drop_2=9999;
$goods_drop_3=9999;

if ($goods_drop_rat4<=2)
{$money_drop=1000;
sql_query("update sys_user set money=(money+$money_drop) where uid='$uid'");
mysql_query("INSERT INTO log_goods (`uid`,`gid`,`count`,`time`,`type`) VALUES ('$uid','-100', '$money_drop','$goods_drop_time','1')");
}


if ($goods_drop_rat1<2)
{
$goods_drop_1=mt_rand(1,146);//道具类
$goods_dropcount_1=mt_rand(1,8);//道具掉落数量
}

if ($goods_drop_rat2<2)
{
$goods_drop_2=mt_rand(10092,10102);//装备类
$goods_dropcount_2=mt_rand(1,6);//装备掉落数量
}

if ($goods_drop_rat3<2)
{
$goods_drop_3=mt_rand(1,4);//任务物品类
$goods_dropcount_3=mt_rand(5,20)*100;//任务物品掉落数量
}


//==============道具物品掉落输出
$goods_dropname_1 =sql_fetch_one_cell("select name from cfg_goods where `gid`='$goods_drop_1'");
$sys_usergoods_gid1 =sql_fetch_one_cell("select gid from sys_goods where uid=$uid and `gid`='$goods_drop_1'");
if($goods_drop_1!=9999)

mysql_query("INSERT INTO log_goods (`uid`,`gid`,`count`,`time`,`type`) VALUES ('$uid','$goods_drop_1', '$goods_dropcount_1','$goods_drop_time','1')");
  
if($goods_dropname_1!="")
	{

  if ($sys_usergoods_gid1!="")
	  {
	sql_query("update sys_goods set count=(count+$goods_dropcount_1) where uid=$uid and gid='$goods_drop_1'");  
      }
   mysql_query("INSERT INTO sys_goods (`uid`,`gid`,`count`) VALUES ('$uid','$goods_drop_1', '$goods_dropcount_1')");//发道具给玩家
    $content1='<tr>
    <td width="130" height="23" align="center" class="TextArmyCount">'.$goods_dropname_1.'</td>
    <td width="130" align="center" class="TextArmyCount">'.$goods_dropcount_1.'</td></tr>';
   }
else


//==============装备物品掉落输出
$goods_dropname_2 =sql_fetch_one_cell("select name from cfg_goods where `gid`='$goods_drop_2'");
$sys_usergoods_gid2 =sql_fetch_one_cell("select gid from sys_goods where uid=$uid and `gid`='$goods_drop_2'");
if ($goods_drop_2!=9999)

mysql_query("INSERT INTO log_goods (`uid`,`gid`,`count`,`time`,`type`) VALUES ('$uid','$goods_drop_2', '$goods_dropcount_2','$goods_drop_time','1')");

  if($goods_dropname_2!="")
      {
   if($sys_usergoods_gid2!="")
	  {
	sql_query("update sys_goods set count=(count+$goods_dropcount_2) where uid=$uid and gid='$goods_drop_2'");
   
   }
	mysql_query("INSERT INTO sys_goods (`uid`,`gid`,`count`) VALUES ('$uid','$goods_drop_2', '$goods_dropcount_2')");//发装备给玩家
$content2='<tr>
    <td width="130" height="23" align="center" class="TextArmyCount">'.$goods_dropname_2.'</td>
    <td width="130" align="center" class="TextArmyCount">'.$goods_dropcount_2.'</td></tr>';
}
else


//==============任务物品掉落输出
$goods_dropname_3 =sql_fetch_one_cell("select name from cfg_things where `tid`='$goods_drop_3'");
$sys_usergoods_tid3 =sql_fetch_one_cell("select tid from sys_things where uid=$uid and `tid`='$goods_drop_3'");
if ($goods_drop_3!=9999)

mysql_query("INSERT INTO log_things (`uid`,`tid`,`count`,`time`,`type`) VALUES ('$uid','$goods_drop_3', '$goods_dropcount_3','$goods_drop_time','1')");
	
if ($goods_dropname_3!="")
  {
   if($sys_usergoods_tid3!="")
	  {
	sql_query("update sys_things set count=(count+$goods_dropcount_3) where uid=$uid and tid='$goods_drop_3'");
   
      }
	mysql_query("INSERT INTO sys_things (`uid`,`tid`,`count`) VALUES ('$uid','$goods_drop_3', '$goods_dropcount_3')");//发任务物品给玩家
$content3='<tr>
    <td width="130" height="23" align="center" class="TextArmyCount">'.$goods_dropname_3.'</td>
    <td width="130" align="center" class="TextArmyCount">'.$goods_dropcount_3.'</td></tr>';
 }
 else


//==============元宝掉落输出

if ($money_drop>0)
{
	
$content4='<tr>
    <td width="130" height="23" align="center" class="TextArmyCount">'.'元宝'.'</td>
    <td width="130" align="center" class="TextArmyCount">'.$money_drop.'</td></tr>';
}



$goods_drop_content='<table width="260" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF"><tr class="TitleBattleYellow">
    <td width="130" height="23" align="center">获得物品名称</td>
    <td width="130" align="center">获得物品数量</td>
  </tr>'.$content1.$content2.$content3.$content4.'</table>';
sql_query("update mem_bin_zhanbao set goods_content='$goods_drop_content' where bid=$g_t_id and state=0 ");

// mysql_close($con);

}















?>
